<template>
  <div class="page">
    <Navbar title="中介基础信息" />
    <!-- <div class="search-header f-r j-b a-c">
      <van-search v-model="searchValue" class="f-g" placeholder="请输入您的搜索内容" @search="onRefresh" />
      <div class="f-r a-c filter-box" @click="show = true">
        <span style="margin-right: 3px">筛选</span>
        <van-image
          width="0.28rem"
          height="0.33rem"
          :src="filterIcon"
        />
      </div>
    </div> -->
    <div class="content">
      <van-pull-refresh v-model="refreshLoading" @refresh="onRefresh">
        <van-empty v-if="!tableData.length" description="暂无数据" />
        <div class="list">
          <div
            v-for="(item,index) in tableData"
            :key="index"
            class="list-item"
            @click="routerJump(item, index + 1)"
          >
            <div v-if="item.icon" class="list-item-header f-r a-c">
              <img :src="item.icon" alt="">
              <span class="title">{{ item.corporateName }}</span>
            </div>
            <div v-else class="list-item-header f-r a-c">
              <span class="title">{{ index + 1 }}、{{ item.corporateName }}</span>
            </div>
            <div class="score f-r a-c">
              综合评分：
              <van-rate
                v-model="item.score"
                allow-half
                :size="12"
                color="#EA9518"
                void-icon="star"
                void-color="#eee"
              />
              <span class="score-value">{{ item.score }}</span>
            </div>
            <div class="list-item-footer f-r a-c j-b">
              <div class="count">
                办件评价量：<span style="color: #2F86FD">{{ item.sum }}</span>件
              </div>
              <div class="tobtn">
                查看中介详情 >
              </div>
            </div>
          </div>
        </div>
      </van-pull-refresh>
    </div>

    <van-popup
     v-model="show"
     position="top"
     :style="{ height: '313px' ,margin:'100px 0'}"
     :overlay-style = "{background: 'rgba(0,0,0,0)'}"
      >
      <div  class="fatherName" v-for="(item,index) in chioceList" :key="index">
        {{ item. approvalDepartment}}
        <div class="childName" v-for="(itemlist,index2) in item.matters":key="index2" :class="[chioceId == itemlist.id?'childchioce':'']" @click="onSelect(itemlist.id)">
          {{ itemlist.serviceMatters }}
        </div>
        </div>
</van-popup>
</div>
</template>

<script>
import refresh from '@/mixins/refresh'
import { http_mediation } from '@/api'
import { Toast } from 'vant'

export default {
  name: 'Mediation',
  mixins: [refresh],
  data() {
    return {
      show: false,
      searchValue: '',
      unitType: {},
      filterIcon: require('@/assets/home/filter.png'),
      tableData: [
      ],
      chioceList: [],
      chioceId: ''
    }
  },
  // created() {
  //   this.getchioce()
  // },
  methods: {
    onSelect(e) {
      console.log(e)
      if (e === this.chioceId) {
        this.chioceId = ''
      } else {
        this.chioceId = e
      }
      this.show = false
      this.onRefresh()
    },
    routerJump(item, index) {
      this.$router.push({
        path: '/mediation-detail',
        query: {
          userId: item.userId,
          id: item.id,
          index: index
        }
      })
    },
    onRefresh() {
      this.pageNo = 1
      this.getList()
    },
    getList() {
      if (this.pageNo > 1 && this.tableData.length >= this.totalSize) return Toast('没有更多了')
      http_mediation.page2({
        serviceMatters: this.$route.query.name
      }).then(res => {
        if (this.pageNo === 1) {
          this.tableData = res.data.records.map((el, index) => {
            return {
              icon: index < 2 ? require(`@/assets/home/top${index + 1}.png`) : '',
              ...el
            }
          })
        } else {
          this.tableData = [
            ...this.tableData,
            ...res.data.records.map(el => {
              return {
                ...el
              }
            })
          ]
        }
        this.totalSize = res.data.total
        this.refreshLoading = false
      })
    }
    // getchioce() {
    //   http_mediation.getInterEvent().then(res => {
    //     this.chioceList = res.data
    //   })
    // }
  }
}
</script>

<style scoped lang="scss">
.page {
    .search-header {
        background-color: #fff;
        padding-right: 0.32rem;
        .filter-box {
            flex-shrink: 0;
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #333333;
        }
    }
    .list {
        .list-item {
            padding: 12px 20px;
            background-color: #fff;
            border-radius: 10px;
            margin-bottom: 20px;
            .list-item-footer {
                .count {
                    font-size: 12px;
                    line-height: 12px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #666666;
                }
                .tobtn {
                    font-size: 12px;
                    line-height: 12px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #2F86FD;
                }
            }
            .list-item-header {
                margin-bottom: 10px;
                img {
                   width: 18px;
                    height: 20px;
                    margin-right: 7px;
                }
                .title {
                    font-size: 16px;
                    line-height: 16px;
                    font-family: PingFang SC;
                    font-weight: 500;
                    color: #333333;
                }
            }

            .score {
                font-size: 12px;
                line-height: 12px;
                font-family: PingFang SC;
                font-weight: 500;
                color: #666666;
                margin-bottom: 13px;
            }
        }
    }
}
.fatherName{
  font-size: 13px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #999999;
  line-height: 31px;
  margin-left: 17px;
  .childName{
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    color: #2F86FD;
    background: #fff;
    // height: 36px;
    line-height: 38px;
    margin-left: 34px;
    margin-right: 17px;
  }
  .childchioce{
    background: #2F86FD;
    color: #fff;
  }
}

</style>
